package com.ziyucoding.springboot.labs.lab4.event.listner;

import com.ziyucoding.springboot.labs.lab4.event.events.MsgEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 信息监听器
 *
 * @author ziyucoding
 * @date 2022-10-25
 **/
@Slf4j
@Component
public class MsgListener {

    @Async
    @EventListener(MsgEvent.class)
    public void sendMsg(MsgEvent event) {
        String orderId = event.getOrderId();
        long start = System.currentTimeMillis();
        log.info("发送短信");
        log.info("发送邮件");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            log.info("线程休眠异常", e);
        }
        long end = System.currentTimeMillis();
        log.info("{}：发送短信、邮件耗时：({})毫秒", orderId, (end - start));
    }

}
